const vm = Vue.createApp({
    data() {
        return {
            blogs: []
        }
    },
    mounted() {
        this.loadBlog()
    },
    methods: {
        // loadBlog() {
        //     axios.get("/api/archives/load").then(res => {
        //         this.blogs = res.data;
        //     })
        // },

        async loadBlog() {
            var res = await axios.get("/api/archives/load");
            this.blogs = res.data;
        },

        async loadMore(index) {
            // const year = this.blogs[index].year;
            // const blogList = this.blogs[index].blogList;
            // const pageMap = this.blogs[index].pageMap;

            // const pageSize = pageMap.pageSize;
            // const pages = pageMap.pages;


            // 用解构实现
            let {year, blogList, pageMap} = this.blogs[index];
            let {pageSize, pages, pageNo: pno} = pageMap;

            const pageNo = pno * 1 + 1;
            if (pageNo > pages) {
                alert("没有更多了...")
                return;
            }

            this.blogs[index].pageMap.pageNo = pageNo;

            try {
                // let res = await axios.get("/api/archives/loadMore?year=" + year + "&pageNo=" + pageNo + "&pageSize=" + pageSize);
                let res = await axios.get(`/api/archives/loadMore?year=${year}&pageNo=${pageNo}&pageSize=${pageSize}`)
                this.blogs[index].blogList = blogList.concat(res.data);
            }catch (e){
                console.log("出错了")
            }
        }
    }
}).mount("#app");